import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  OneToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from "typeorm";
import { Class } from "src/school/class/entities/class.entity";
import { TeacherDetail } from "./teacherDetail.entity";
import { CourseEnum } from "src/enums/school/course.enum";

@Entity()
export class Teacher {
  //自增列
  @PrimaryGeneratedColumn()
  id: number;

  //普通列
  @Column({ comment: "教师名称" })
  teacherName: string;

  // 如果是 type 类型,则必须数组包裹
  @Column({ comment: "负责课程", type: "enum", enum: Object.values(CourseEnum) })
  course: `${CourseEnum}`;

  @Column({ comment: "创建人", default: null })
  createBy: string;

  @Column({ comment: "创建人id", default: null })
  createById: number;

  @CreateDateColumn({ comment: "账号创建时间" })
  createDate: Date;

  @Column({ comment: "更新人", default: null })
  updateBy: string;

  @Column({ comment: "更新人id", default: null })
  updateById: number;

  @UpdateDateColumn({ comment: "账号更新时间" })
  updateDate: Date;

  @OneToOne(() => TeacherDetail, {
    eager: true, // 如果需要立即加载关联实体，可以设置为true
    cascade: true, // 如果需要级联保存/更新/删除，可以添加相应的选项
  })
  @JoinColumn()
  detail: TeacherDetail;

  @ManyToMany(() => Class, classEntity => classEntity.teachers)
  // @JoinTable({ name: "class_teacher" }) // ! 别两边指定 血泪的教训
  classes: Class[];
}
